package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import android.widget.Toast;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

public class AddItemsActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText editText;
    private  EditText editText2;
    private EditText editText3;
    private EditText editText4;

    private Button button3;
    private  Button button4;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_items);
        initView();
    }

    private void initView() {
        editText =  findViewById(R.id.editText);
        editText2 = findViewById(R.id.editText2);
        editText3 = findViewById(R.id.editText3);
        editText4 = findViewById(R.id.editText4);
        button3 = findViewById(R.id.button3);
        button4 = findViewById(R.id.button4);

        button3.setOnClickListener( this);
        button4.setOnClickListener( this);
    }
    public void onClick(View v)  {
        switch (v.getId()){
            case R.id.button3:
                String name = editText.getText().toString();
                String desc = editText2.getText().toString();
                String remark = editText3.getText().toString();
                String price = editText4.getText().toString();

                Map<String, String> map = new HashMap<>();
                map.put("itemName",name);
                map.put("itemDesc",desc);
                map.put("itemRemark",remark);
                map.put("initPrice", price);
                map.put("kindId","1");
                map.put("avail","1");
        try {
            String result = OkHttpUtil.postRequest("http://172.18.85.254:8080/auction/api/items", map);
            Toast.makeText(this, result, Toast.LENGTH_LONG).show();
        }catch (ExecutionException e){
            e.printStackTrace();
        }catch (InterruptedException e){
            e.printStackTrace();
        }

        break;
            case R.id.button4:
                Intent intent = new Intent(this,ItemActivity.class);
                startActivity(intent);
                break;
        }
    }

}
